Skip to content

Conversation

ochafik
Copy link
Contributor

@ochafik ochafik commented Oct 1, 2025

Motivation and Context

Most clients don't implement sampling yet, which complicates development and adoption of sampling.
This simple example shows how to wrap an stdio server invocation in a proxy that backfills (the context-free subset of) the sampling feature using the Claude API (needs ANTHROPIC_API_KEY environment variable).

Additional context:

cc/ @bhosmer-ant

How Has This Been Tested?

  • Check out everything.sampleLLM: add includeContext & preferredModelName params servers#2802 and add the following run-stdio.sh script to it:

    #!/bin/bash
    set -euo pipefail
    
    cd "$(dirname "$0")"
    npm i >&2
    npm run build >&2
    npm run --silent start
  • Run:

        npx -y @modelcontextprotocol/inspector \
          npx -y --silent tsx src/examples/backfill/backfillSampling.ts \
            ...path..to...modelcontextprotocol/servers/src/everything/run-stdio.sh

Breaking Changes

none

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@ochafik ochafik requested review from a team and felixweinberger October 1, 2025 14:23
@ochafik ochafik changed the title add sampling backfill example add (context-free) sampling backfill example Oct 1, 2025
Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ochafik , I think this is a great example, but I don't think we should add Anthropic API dependency to the SDK, even if it's a dev dependency

@ihrpr
Copy link
Contributor

ihrpr commented Oct 1, 2025

would it make sense to have a separate small repo demo and a blog post about it?

@ochafik
Copy link
Contributor Author

ochafik commented Oct 1, 2025

would it make sense to have a separate small repo demo and a blog post about it?

@ihrpr Makes sense, thanks! Actually my motivation was to serve as the baseline of a utility for #991, so will close this for now / decide if we want to blog before/after the sampling improvements sep gets some decision.

@ochafik ochafik closed this Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants